//
//  YLLAuthorityManager.m
//  yilule
//
//  Created by lidi on 16/3/18.
//  Copyright © 2016年 topview. All rights reserved.
//

#import "YLLAuthorityManager.h"


@implementation YLLAuthorityManager

+ (BOOL)authorityWithType:(YLLAuthorityType)type_
{
    switch (type_) {
        case YLLAuthorityType_PushNotification:
        {
            //iOS8 check if user allow notification
            //check systemVerson of device
            UIDevice *device = [UIDevice currentDevice];
            float sysVersion = [device.systemVersion floatValue];
            if (sysVersion >= 8.0f)
            {
                // system is iOS8
                UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
                if (UIUserNotificationTypeNone != setting.types) {
                    return YES;
                }
            }
            else
            {
                //iOS7
                #pragma clang diagnostic push
                #pragma clang diagnostic ignored"-Wdeprecated-declarations"
                UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
                if(UIRemoteNotificationTypeNone != type)
                    return YES;
                #pragma clang diagnostic pop

            }
            
            return NO;
        }
            break;
        case YLLAuthorityType_Locate:
        {
        }
            break;
        case YLLAuthorityType_Contacts:
        {
        }
            break;
        case YLLAuthorityType_Camera:
        {
        }
            break;
        case YLLAuthorityType_PhotoGallery:
        {
            
        }
            break;
        case YLLAuthorityType_Microphone:
        {

        }
            break;
        default:
            break;
    }
    
    return NO;
}

+ (void)noticeAuthorityWithType:(YLLAuthorityType)type_
{
    UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];

    switch (type_) {
        case YLLAuthorityType_PushNotification:
        {
            controller.title = @"推送服务已关闭";
            controller.message = @"请到设置>隐私>推送中开启[一路乐旅游]推送服务，以便获得更好的旅游体验";
        }
            break;
        case YLLAuthorityType_Locate:
        {


        }
            break;
        case YLLAuthorityType_Contacts:
        {
            controller.title = @"需要开启您的通讯录权限";
            controller.message = @"请到设置>隐私>通讯录中开启[一路乐旅游]通讯录权限，以便获得更好的旅游体验";
        }
            break;
        case YLLAuthorityType_Camera:
        {
            controller.title = @"需要开启您的照相机权限";
            controller.message = @"请到设置>隐私>照相机中开启[一路乐旅游]照相机权限，以便获得更好的旅游体验";
        }
            break;
        case YLLAuthorityType_PhotoGallery:
        {
            controller.title = @"需要开启您的相册权限";
            controller.message = @"请到设置>隐私>相册中开启[一路乐旅游]相册权限，以便获得更好的旅游体验";
        }
            break;
        case YLLAuthorityType_Microphone:
        {
            controller.title = @"需要开启您的麦克风权限";
            controller.message = @"请到设置>隐私>麦克风中开启[一路乐旅游]麦克风权限，以便获得更好的旅游体验";
        }
            break;
        default:
            break;
    }
    
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *settingAction = [UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
        });
    }];
}

@end
